package com.chushouya.manager.service.api.impl;

import com.chushouya.manager.dao.entity.UserEntity;
import com.chushouya.manager.dao.repository.UserRepository;
import com.chushouya.manager.dto.api.setting.SettingItemDTO;
import com.chushouya.manager.service.api.SettingApiService;
import com.general.framework.core.lang.Validate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 设置接口服务实现类
 * 提供设置相关数据查询功能
 * 
 * @author chushouya
 */
@Service
public class SettingApiServiceImpl implements SettingApiService {

    @Resource
    private UserRepository userRepository;

    @Override
    public List<SettingItemDTO> getSettingList(Long userId) {
        Validate.isNull(userId, "用户ID不能为空");
        
        List<SettingItemDTO> settingList = new ArrayList<>();
        
        // 查询用户信息
        UserEntity userEntity = userRepository.selectByPrimaryKey(userId);
        String userName = Objects.nonNull(userEntity) ? userEntity.getUserName() : "";
        
        // 用户账号设置项
        settingList.add(new SettingItemDTO(100001L, "用户账号","1", 1, userName));
        
        // 密码管理设置项
        boolean hasPassword = Objects.nonNull(userEntity) && Objects.nonNull(userEntity.getPassword()) 
                && !userEntity.getPassword().isEmpty();
        if (hasPassword) {
            // 已设置密码，显示修改密码
            settingList.add(new SettingItemDTO(100004L, "修改密码", "1",2, "", "/pages/user/updatePassword"));
        } else {
            // 未设置密码，显示设置密码
            settingList.add(new SettingItemDTO(100004L, "设置密码","1", 2, "", "/pages/user/setPassword"));
        }
        
        // 用户协议设置项
        settingList.add(new SettingItemDTO(100002L, "用户协议","2", 2, "", "/pages/article/info?id=100009"));
        
        // 隐私协议设置项
        settingList.add(new SettingItemDTO(100005L, "隐私协议简要版","2", 2, "", "/pages/article/info?id=100012"));
        settingList.add(new SettingItemDTO(100003L, "隐私协议","2", 2, "", "/pages/article/info?id=100010"));
        settingList.add(new SettingItemDTO(100016L, "个人信息收集清单","2", 2, "", "/pages/personal/index"));
        settingList.add(new SettingItemDTO(100013L, "个人信息共享清单","2", 2, "", "/pages/article/info?id=100013"));
        settingList.add(new SettingItemDTO(100014L, "用户权限列表","2", 2, "", "/pages/article/info?id=100014"));

        settingList.add(new SettingItemDTO(100015L, "注销用户","3", 2, "", "/pages/close/index"));

        return settingList;
    }
}
